package com.cskaoyan.market.service;

import com.cskaoyan.market.db.domain.MarketAdmin;
import com.cskaoyan.market.db.domain.MarketAdminExample;
import com.cskaoyan.market.db.mapper.MarketAdminMapper;
import com.cskaoyan.market.util.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

/**
 * @ClassName AdminServiceImpl
 * @Description: TODO
 * @Author 远志 zhangsong@cskaoyan.onaliyun.com
 * @Date 2024/3/14 11:08
 * @Version V1.0
 **/
public class AdminServiceImpl implements AdminService {
    @Override
    public MarketAdmin login(String username, String password) {
        SqlSession session = MybatisUtils.getSession();
        MarketAdminMapper adminMapper = session.getMapper(MarketAdminMapper.class);
        //根据用户名、密码进行查询
        MarketAdminExample marketAdminExample = new MarketAdminExample();
        //标准、准则，里面用来去拼接条件
        MarketAdminExample.Criteria criteria = marketAdminExample.createCriteria();
        //链式调用的效果 select * from market_admin where username = ? and password = ?
        criteria.andUsernameEqualTo(username).andPasswordEqualTo(password);
        MarketAdmin admin = adminMapper.selectOneByExample(marketAdminExample);
        session.close();
        return admin;
    }
}
